using System.Runtime.CompilerServices;

namespace DocumentMakingTools.CustomControls;

public partial class LogoView : ContentView
{
	public static readonly BindableProperty LogoSizeProperty = BindableProperty.Create(nameof(LogoSize), typeof(double), typeof(LogoView), propertyChanged: OnLogoSizeChanged);
	public static readonly BindableProperty ShowHansProperty = BindableProperty.Create(nameof(ShowHans), typeof(bool), typeof(LogoView), propertyChanged: OnShowHansChanged);
	public double LogoSize
	{
		get { return (double)GetValue(LogoSizeProperty); }
		set { SetValue(LogoSizeProperty, value); }
	}
	public bool ShowHans
	{
		get => (bool)GetValue(ShowHansProperty);
		set => SetValue(ShowHansProperty, value);
	}
	public LogoView()
	{
		InitializeComponent();

		LabelLogo.FontSize = 20;
		LabelHans.FontSize = LabelLogo.FontSize / 3.0;
		LabelHans.IsVisible = false;
	}
	static void OnLogoSizeChanged(BindableObject bindable, object oldValue, object newValue)
	{
		if (oldValue is null || newValue is null)
			return;
        var logoView = (LogoView)bindable;
		var fontSize = (double)newValue;
		logoView.LabelLogo.FontSize = fontSize;
        logoView.LabelHans.FontSize = fontSize / 3.0;
    }
	static void OnShowHansChanged(BindableObject bindable, object oldValue, object newValue)
	{
        if (oldValue is null || newValue is null)
            return;
		var logoView = (LogoView)bindable;
		logoView.LabelHans.IsVisible = (bool)newValue;
    }
}